package com.edu.study.base.StuQuestionPaper.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.edu.study.base.StuQuestionPaper.domain.StuQuestionPaper;
import com.edu.study.base.StuQuestionPaper.service.IStuQuestionPaperService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题卷Controller
 * 
 * @author jjt
 * @date 2021-05-20
 */
@RestController
@RequestMapping("/study/StuQuestionPaper")
public class StuQuestionPaperController extends BaseController
{
    @Autowired
    private IStuQuestionPaperService stuQuestionPaperService;

    /**
     * 查询题卷列表
     */
    @PreAuthorize("@ss.hasPermi('study:StuQuestionPaper:list')")
    @GetMapping("/list")
    public TableDataInfo list(StuQuestionPaper stuQuestionPaper)
    {
        startPage();
        List<StuQuestionPaper> list = stuQuestionPaperService.selectStuQuestionPaperList(stuQuestionPaper);
        return getDataTable(list);
    }

    /**
     * 导出题卷列表
     */
    @PreAuthorize("@ss.hasPermi('study:StuQuestionPaper:export')")
    @Log(title = "题卷", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StuQuestionPaper stuQuestionPaper)
    {
        List<StuQuestionPaper> list = stuQuestionPaperService.selectStuQuestionPaperList(stuQuestionPaper);
        ExcelUtil<StuQuestionPaper> util = new ExcelUtil<StuQuestionPaper>(StuQuestionPaper.class);
        return util.exportExcel(list, "StuQuestionPaper");
    }

    /**
     * 获取题卷详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:StuQuestionPaper:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(stuQuestionPaperService.selectStuQuestionPaperById(id));
    }

    /**
     * 新增题卷
     */
    @PreAuthorize("@ss.hasPermi('study:StuQuestionPaper:add')")
    @Log(title = "题卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StuQuestionPaper stuQuestionPaper)
    {
        return toAjax(stuQuestionPaperService.insertStuQuestionPaper(stuQuestionPaper));
    }

    /**
     * 修改题卷
     */
    @PreAuthorize("@ss.hasPermi('study:StuQuestionPaper:edit')")
    @Log(title = "题卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StuQuestionPaper stuQuestionPaper)
    {
        return toAjax(stuQuestionPaperService.updateStuQuestionPaper(stuQuestionPaper));
    }

    /**
     * 删除题卷
     */
    @PreAuthorize("@ss.hasPermi('study:StuQuestionPaper:remove')")
    @Log(title = "题卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stuQuestionPaperService.deleteStuQuestionPaperByIds(ids));
    }
}
